<%@page import="team02.server.bean.TestBean"%>
<%@page import="team02.client.core.test.Test"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>

<script>
	setTitle("Login");
	function retryLogin() {
		alert("ログイン名またはパスワードが違いました");

	}
</script>

<link rel="stylesheet"	href="${pageContext.request.contextPath}/css/template.css">
<link rel="stylesheet"	href="${pageContext.request.contextPath}/css/login.css">
	
<jsp:setProperty property="*" name="userBean" />
<jsp:setProperty property="*" name="examineeBean" />
<jsp:setProperty property="aliasRequest" param="aliasRequest" name="userBean" />

<%
	if("test_page.t02".equals(request.getParameter("prev"))){
		userBean.clear();
		String userId = request.getParameter("u");
		String time = request.getParameter("t");
		if(!StringUtils.isEmpty(userId) && !StringUtils.isEmpty(time)){

			TestBean testBean = new TestBean();
			testBean.setCreatedBy(Integer.parseInt(userId));
			testBean.setCreatedTime(Long.parseLong(time));
			if(0 == testBean.load()){
				examineeBean.setTestId(testBean.getTest().getId());
				examineeBean.load();
				if(examineeBean.getId() != 0){
					response.sendRedirect("test_page.t02?u=" + userId + "&t=" + time);
				}
			}
			if(examineeBean.getUsername() != null || examineeBean.getPassword() != null){
				userBean.clear();
				%>			
				<script>
					retryLogin();
				</script>
				<%			
			}			
		}
	} else{
		examineeBean.clear();
		userBean.load();
		if (userBean.getUserId() != 0) {
			response.sendRedirect("manager.t02");
		} else if (userBean.getUsername() != null || userBean.getPassword() != null) {

			userBean.clear();
			%>
			<script>
				retryLogin();
			</script>
			<%
		}
	}
%>
<div class="container" style="height: 400px">
	<h1>ログイン</h1>
	<div class="login">
		<form action="#" method="post" name="login">
			<table width="310px" cellpadding="0" cellspacing="0">
				<tr>
					<td>
						<p class="label">ログイン名 ：</p>
					</td>
					<td><input type="text" placeholder="あなたのログイン名"
						name="username" id="username" required="required"
						value="${userBean.username }" /></td>
				</tr>
				<tr>
					<td>
						<p class="label">パスワード：</p>
					</td>
					<td><input type="password" placeholder="あなたのパスワード"
						name="password" id="password" required="required"
						value="${userBean.password }" /></td>
				</tr>
				<tr>
					<td colspan="2">


						<p class="submit">
							<input type="submit" name="loginButton" value="ログイン"/>
						</p>
					</td>
				</tr>

			</table>
		</form>
	</div>
</div>




